import {ref} from "vue"

export interface KillLevelType {
    level: number;
    name: string;
    desc: string;
    exp: number;
}

export const killLevel = [
    {
        "level": 1,
        "name": "初学乍练",
        "desc": "刚刚入门，只能勉强施展，效果微弱，成功率低。",
        "exp": 100,
    },
    {
        "level": 2,
        "name": "粗通皮毛",
        "desc": "掌握基础用法，但不够熟练，偶尔会失败或效果不稳定。",
        "exp": 300,
    },
    {
        "level": 3,
        "name": "登堂入室",
        "desc": "能正常使用，但缺乏变化，威力一般。",
        "exp": 600,
    },
    {
        "level": 4,
        "name": "略有小成",
        "desc": "可以灵活运用，效果增强，开始掌握一些进阶技巧。",
        "exp": 1000,
    },
    {
        "level": 5,
        "name": "驾轻就熟",
        "desc": "运用自如，威力显著提升，能适应不同战斗环境。",
        "exp": 1500,
    },
    {
        "level": 6,
        "name": "炉火纯青",
        "desc": "接近完美掌握，技能附带额外效果（如暴击、穿透、特殊属性）。",
        "exp": 2200,
    },
    {
        "level": 7,
        "name": "出神入化",
        "desc": "超越常规理解，技能可能变异或附带特殊能力（如范围扩大、持续伤害）。",
        "exp": 3000,
    },
    {
        "level": 8,
        "name": "超凡入圣",
        "desc": "突破极限，技能产生质变（如附带法则之力、无视部分防御）。",
        "exp": 4000,
    },
    {
        "level": 9,
        "name": "返璞归真",
        "desc": "化繁为简，技能威力极大，甚至影响环境或规则（如短暂时间停滞、空间扭曲）。",
        "exp": 5200,
    },
    {
        "level": 10,
        "name": "大道至简",
        "desc": "技能达到极致，近乎神通，可影响世界法则（如改写现实、创造/毁灭小世界）。",
        "exp": 6600,
    }
]

export const useZhongzhiStore = defineStore('zhongzhiStore', () => {
    const skillName = ref("种植")
    const skillInfo = ref({
        expAll: 0,
        level: 1,
        name: "",
        desc: "",
    })
    // 当前升级需要的经验值和拥有的经验值
    const needExp = ref({
        current: 0,
        all: 0,
    })
    // 增加技能经验
    const addSkillExp = (exp: number=0) => {
        skillInfo.value.expAll += exp
        getSkillLevel()

    }
    const getSkillLevel = () => {
        for (let i = 0; i < killLevel.length; i++) {
            if (skillInfo.value.expAll < killLevel[i].exp) {
                skillInfo.value.level = killLevel[i].level
                skillInfo.value.name = killLevel[i].name
                skillInfo.value.desc = killLevel[i].desc
                break
            }
        }
    }
    // 初始化
    const initFunc=()=>{
        addSkillExp()
    }
    return {
        skillName,
        skillInfo,
        needExp,
        addSkillExp,
        initFunc,
    }
})


export const useZhiyaoStore = defineStore('zhiyaoStore', () => {
    const skillName = ref("制药")
    const skillInfo = ref({
        expAll: 0,
        level: 1,
        name: "",
        desc: "",
    })
    // 当前升级需要的经验值和拥有的经验值
    const needExp = ref({
        current: 0,
        all: 0,
    })
    // 增加技能经验
    const addSkillExp = (exp: number=0) => {
        skillInfo.value.expAll += exp
        getSkillLevel()

    }
    const getSkillLevel = () => {
        for (let i = 0; i < killLevel.length; i++) {
            if (skillInfo.value.expAll < killLevel[i].exp) {
                skillInfo.value.level = killLevel[i].level
                skillInfo.value.name = killLevel[i].name
                skillInfo.value.desc = killLevel[i].desc
                break
            }
        }
    }
    // 初始化
    const initFunc=()=>{
        addSkillExp()
    }
    return {
        skillName,
        skillInfo,
        needExp,
        addSkillExp,
        initFunc,
    }
})

export const useZhiqiStore = defineStore('zhiqiStore', () => {
    const skillName = ref("制器")
    const skillInfo = ref({
        expAll: 0,
        level: 1,
        name: "",
        desc: "",
    })
    // 当前升级需要的经验值和拥有的经验值
    const needExp = ref({
        current: 0,
        all: 0,
    })
    // 增加技能经验
    const addSkillExp = (exp: number=0) => {
        skillInfo.value.expAll += exp
        getSkillLevel()

    }
    const getSkillLevel = () => {
        for (let i = 0; i < killLevel.length; i++) {
            if (skillInfo.value.expAll < killLevel[i].exp) {
                skillInfo.value.level = killLevel[i].level
                skillInfo.value.name = killLevel[i].name
                skillInfo.value.desc = killLevel[i].desc
                break
            }
        }
    }
    // 初始化
    const initFunc=()=>{
        addSkillExp()
    }
    return {
        skillName,
        skillInfo,
        needExp,
        addSkillExp,
        initFunc,
    }
})